#!/usr/local/ruby
require 'pp'
require 'pathname'
avis = Dir.glob("/mnt/**/*.wmv")
totalcnt = avis.size

count = 0 
avis.each{|fn|
    count = count + 1 
    out_file =fn.gsub '/', '_' 
    File.delete "./#{out_file}" if File.exists? "./#{out_file}" 
    p = Pathname.new fn
    puts "#{"%05d" % count}/#{totalcnt} encode #{fn}: size #{p.size / 1024 / 1024.0} MB"
    puts `mencoder #{fn} -o ./#{out_file}.flv -of lavf \
        -mc 0 -audio-preload 0.0 -ofps 30.000 -ovc lavc \
        -lavcopts vcodec=flv -lavcopts vbitrate=1000  -srate 44100 \
        -oac mp3lame -lameopts vbr=0  -lameopts br=128 -lameopts vol=0 \
        -lameopts mode=1 -lameopts aq=7 -lameopts padding=3 -af volnorm -noskip`
        
#    -oac mp3lame -lameopts abr:br=56 -srate 22050 -ovc lavc \
#    -lavcopts vcodec=flv:vbitrate=1800:mbd=2:mv0:trell:v4mv:cbp:last_pred=3 \
#    -noskip -mc 0`
    }   
